package com.dwd.basic.controller;

import com.dwd.basic.service.IVerification;
import com.dwd.basic.utils.AjaxResult;
import com.dwd.user.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: TODO
 * @Author 汶狄
 * @Date 2021/1/16 14:03
 * @Version 1.0
 */
@RestController
@RequestMapping("/verification")
public class VerificationCodeController {
    @Autowired
    private IVerification verification;

    /**
     * 注册发送验证码
     *
     * @param user
     * @return
     */
    @PostMapping("/sendMobileCode")
    public AjaxResult sendMobileCode(@RequestBody User user) {
        try {
            verification.sendMobileCode(user.getPhone());
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(e.getMessage());
        }
    }

    /**
     * 绑定发送验证码
     *
     * @param user
     * @return
     */
    @PostMapping("/sendBinderVerificationCode")
    public AjaxResult sendBinderVerificationCode(@RequestBody User user) {
        try {
            verification.sendBinderVerificationCode(user.getPhone());
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(e.getMessage());
        }
    }

    /**
     * 发送邮箱验证码
     * @param user
     * @return
     */
    @PostMapping("/sendEmailVerificationCode")
    public AjaxResult sendEmailVerificationCode(@RequestBody User user) {
        try {
            verification.sendEmailVerificationCode(user.getEmail());
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(e.getMessage());
        }
    }
}
